package com.fenqing.leetcode.code.t400_500;

import com.fenqing.annotations.Execute;
import com.fenqing.core.Topic;

public class Topic494 extends Topic {
    /**
     * 构造器
     *
     * @param input1 输入
     * @param input2
     */
    public Topic494(String input1, String input2) {
        super(input1, input2);
    }

    int count;

    @Execute
    public int findTargetSumWays(int[] nums, int target) {
        findTargetSumWays(nums, 0, 0, target);
        return count;
    }

    public void findTargetSumWays(int[] nums, int i,  int sum, int target) {
        if (i == nums.length){
            if (sum == target) {
                count++;
            }
            return;
        }
        findTargetSumWays(nums, i + 1, sum + nums[i], target);
        findTargetSumWays(nums, i + 1, sum - nums[i], target);
    }

    public static void main(String[] args) {
        Topic494 topic494 = new Topic494("""
                [1]
                """, "1");
        Integer run = topic494.run();
        System.out.println(run);
    }
}
